package cn.blnp.net.flowable.ext.child.transaction;

import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.BpmnError;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;

/**
 * <h3></h3>
 *
 * @author <a href="mailto:blnp.yibin@qq.com">lyb</a>
 * @version 1.0
 * @since 2025/5/20 14:13
 */
@Slf4j
@Component
public class TreasuryDeductService implements JavaDelegate {

    /**
     *  库存
     **/
    int goodsTreasury = 10;

    @Override
    public void execute(DelegateExecution execution) {
        int goodsNum = (Integer) execution.getVariable("goodsNum");
        if (goodsNum > goodsTreasury) {
            log.error("库存不足，订单将取消！");
            throw new BpmnError("500");
        } else {
            log.info("库存充足，订单即将发货！");
        }
    }
}
